Groups, alternatives and back references

Groups -- enclosed in \parentheses -- \(...\)
Alternatives -- \pipe -- \|
Back references -- \1...\9

Groups enclosed in \(...\) serve three purposes

- To group an expression so that it can be treated as if it were a single character. For example, a group will be governed by a quantifier like * as if it were a single character:
Thus, ba\(na\)* matches

ba , bana , banana , bananana , etc.
- To enclose a set of \| alternatives.
For example, my\(foo\|bar\) matches either myfoo or mybar .
The alternation (\|) applies to the largest possible surrounding expressions. Only a surrounding \( ... \) grouping can limit the grouping power of \|.
- To mark a matched substring for back references. The first nine groups in a regex can be referenced using \1 through \9.
For example, \(.*\)\1 will match any string that is composed of two identical halves. The \(.*\) matches the first half, which can be anything (except newline), but the \1 that follows must match the exact text matched by the \(.*\) group.
Groups, alternation and back references can be useful in find/change operations either for global editing in the Retriever or in the Source Editor's Find/Change dialog.
Examples

This example matches

SetupMenu or SetupStyles and
changes Setup to Update
concatenates this with Menu or Styles (whichever was matched) and
adds the substring Always at the end.

Find: | Setup\(Menu\|Styles\)
Change to: | Update\1Always

Good results
Found

Do SetupMenu and changed to Do UpdateMenuAlways
Found SetupStyles and changed to UpdateStylesAlways

Potential pitfall
Found SetupMenu

Styles and changed to UpdateMenuAlways Styles
Remember: "The first match always wins."

- This example matches
foo(parameter1,parameter2) and changes the parameter order. Nonprinting characters are not taken into account, nor are nested parentheses considered.

Find: | <foo(\([^,]+\), \([^,]+\)
Change to: | foo(\2,\1)

Good results
Found foo(a,b) and changed to foo(b,a)
Found foo(int a,char* b) and changed to foo(char* b,int a)

Potential pitfall
Found foo(f(x,y)

,int b) and changed to foo(y),f(x ,int b)
You could of course "fix" the regex by matching ';' at the end, but that does not solve the actual problem. As always, it's safer to check before globally changing things.
Regular expressions are cumbersome for nested parentheses of any depth, and cannot handle arbitrary depths.